package com.flow.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.exception.BusinessException;
import com.apache.ius.plugin.CustomMethodPlugin;
import com.apache.ius.plugin.IusPluginUtil;
import com.apache.tools.DataMap;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 待办任务插件
 * @Author IUS platform administrators create generation
 * @Date 2018-11-16 14:05:35
 */
public class FlowSearchPluginImpl implements CustomMethodPlugin {
	private Logger log = Logger.getLogger(getClass());

	@Override
	public Object beforeInvoke(Map<String, Object> param) {
		log.info("start->> 执行插件事前方法....");

		String sysName = String.valueOf(param.get("sysName"));
		String auditType =  String.valueOf(param.get("auditType"));

		if(Validator.isNull(sysName)){
			throw new BusinessException("sysName参数不能为空！");
		}
		if(Validator.isNull(auditType)){
			throw new BusinessException("auditType参数不能为空！");
		}

		Map<String, Object> whereMap = new HashMap<String, Object>();
		whereMap.put("sysAuditFlow.w_sysName", sysName);
		if(!"all".equals(auditType)){
			whereMap.put("sysAuditFlow.w_auditType", auditType);
		}
		ResultEntity resultEntity = IusPluginUtil.getInstance().select("list","s_sysAuditFlow",whereMap);
		List<DataMap> ruleList = (List<DataMap>) resultEntity.getEntity();//获取该标识下定义的所有规则
		int size = ruleList.size();
		//只有size大于0时才证明该请求正确
		if(size>0){
			if(!"all".equals(auditType)) {
				param.put("sysAudit.w_auditType", auditType);
			}
			param.put("sysAudit.w_auditStatus", "10");
		 }else{
			throw new BusinessException("非法请求！");
		}


		return null;
	}

	@Override
	public Object doInvoke(Map<String, Object> param) {
		log.info("start->> 执行插件方法....");

		return null;
	}

	@Override
	public Object afterInvoke(Map<String, Object> param) {
		log.info("start->> 执行插件事后方法....");

		return null;
	}

	/**
	 * 规则校验统一入口
	 * @param paramsVo
	 */
	public void run(ParamsVo paramsVo) {
		beforeInvoke(paramsVo.getParams());
	}


}

